package sf01.studentmngmsystem.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import sf01.studentmngmsystem.service.StudentService;

@Component
@Slf4j
public class StudentStatisticsTask {
    
    @Autowired
    private StudentService studentService;
    
    // 每天凌晨1点执行统计
    @Scheduled(cron = "0 0 1 * * ?")
    public void generateDailyStatistics() {
        try {
            int totalStudents = studentService.getTotalCount(null, null, null);
            log.info("每日统计 - 学生总数: {}", totalStudents);
            
            // 可以添加更多统计逻辑，如按专业统计、按班级统计等
            
        } catch (Exception e) {
            log.error("生成每日统计报告失败", e);
        }
    }
    
    // 每小时清理临时文件
    @Scheduled(fixedRate = 3600000) // 1小时
    public void cleanupTempFiles() {
        log.info("执行临时文件清理任务");
        // 清理上传目录中的临时文件
    }
}